# # Miahx© 框架消息的 FastDDS C++ API 构建文件
#
# Version: 0.4.10,
# Last updated: October 19, 2024
#
# ## Contributor(s)
# * YAO Naiming <[naiming@iscas.ac.cn](mailto:naiming@iscas.ac.cn)>
#
# ## Change log
# ### v0.4.10
# - .19: [优化] 调整目标（target）的结构
# ### v0.4.7
# - .26: [新增] 初始实现
#
# Copyright (c) All contributors, ISCAS & ASIC. 2024.
# All rights reserved. Licensed under Apache-2.0.

cmake_minimum_required(VERSION 3.22)


# SWIG: use standard target name.
if(POLICY CMP0078)
    cmake_policy(SET CMP0078 NEW)
endif()

# SWIG: use SWIG_MODULE_NAME property.
if(POLICY CMP0086)
    cmake_policy(SET CMP0086 NEW)
endif()


# TARGET: miahx_fastdds_api.dll
project(miahx_fastdds_api)

find_package(fastcdr REQUIRED)
find_package(fastrtps REQUIRED)

set(CMAKE_POSITION_INDEPENDENT_CODE ON)

add_library(${PROJECT_NAME} SHARED
        src/miahx_fastdds_types/MiahxFastDDSTypes.cxx
        src/miahx_fastdds_types/MiahxFastDDSTypesPubSubTypes.cxx
        src/miahx_fastdds_api/src/participant.cpp
        src/miahx_fastdds_api/src/reader.cpp
        src/miahx_fastdds_api/src/bng_classical_reader.cpp
        src/miahx_fastdds_api/src/point_cloud_reader.cpp
        src/miahx_fastdds_api/src/user_reader.cpp
        src/miahx_fastdds_api/src/miahx_c_wrapper.cpp
        src/miahx_fastdds_api/src/miahx_cpp_wrapper.cpp
        src/miahx_fastdds_api/src/miahx_nodejs_wrapper.cpp
)

if(WIN32)
    target_compile_definitions(${PROJECT_NAME} PRIVATE EPROSIMA_USER_DLL_EXPORT)
    target_compile_definitions(${PROJECT_NAME} PRIVATE MIAHX_WRAPPER_DLL_EXPORT)
endif(WIN32)

set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 11)

target_include_directories(${PROJECT_NAME} PUBLIC
        src/miahx_fastdds_types
)

target_link_libraries(${PROJECT_NAME}
        PUBLIC
        fastcdr
        fastrtps
)


# Install
set(CMAKE_INSTALL_PREFIX ../build)
install(TARGETS ${PROJECT_NAME}
        RUNTIME DESTINATION bin/${CMAKE_BUILD_TYPE}
        LIBRARY DESTINATION lib/
        ARCHIVE DESTINATION lib/
)
install(DIRECTORY ${PROJECT_SOURCE_DIR}/src/miahx_fastdds_api/include
        DESTINATION .)
install(FILES ${PROJECT_SOURCE_DIR}/src/miahx_fastdds_types/MiahxFastDDSTypes.h
              ${PROJECT_SOURCE_DIR}/src/miahx_fastdds_types/MiahxFastDDSTypesPubSubTypes.h
        DESTINATION include/miahx)


# TARGET: TEST_CASES
add_executable(TEST_ALL test/test_all.cpp)
target_link_libraries(TEST_ALL
        PUBLIC
        fastcdr
        fastrtps
        miahx_fastdds_api
)

# TARGET: TEST_C_WRAPPER
add_executable(TEST_C_WRAPPER
        test/test_c_wrapper.cpp)
target_include_directories(TEST_C_WRAPPER PUBLIC
        build/include
)
target_link_libraries(TEST_C_WRAPPER
        PUBLIC
        fastcdr
        fastrtps
        miahx_fastdds_api
)

# TARGET: TEST_CPP_WRAPPER
add_executable(TEST_CPP_WRAPPER
        test/test_cpp_wrapper.cpp)
target_include_directories(TEST_CPP_WRAPPER PUBLIC
        build/include
)
target_link_libraries(TEST_CPP_WRAPPER
        PUBLIC
        fastcdr
        fastrtps
        miahx_fastdds_api
)

# TARGET: TEST_NODEJS_WRAPPER
add_executable(TEST_NODEJS_WRAPPER test/test_nodejs_support.cpp)
target_link_libraries(TEST_NODEJS_WRAPPER
        PUBLIC
        fastcdr
        fastrtps
        miahx_fastdds_api
)